FROM nginx:latest

COPY ./docker-entrypoint.sh /dify-docker-entrypoint.sh

COPY ./conf.d/nginx.conf.template /etc/nginx/conf.d/nginx.conf.template
COPY ./conf.d/proxy.conf.template /etc/nginx/conf.d/proxy.conf.template
COPY ./conf.d/https.conf.template /etc/nginx/conf.d/https.conf.template
COPY ./conf.d/default.conf.template /etc/nginx/conf.d/default.conf.template

##CAE_COMMON_VARS_PLACE_HOLDER##

##DIFY_COMMON_VARS_PLACE_HOLDER##

ENV NGINX_SERVER_NAME=${NGINX_SERVER_NAME:-_} \
    NGINX_HTTPS_ENABLED=${NGINX_HTTPS_ENABLED:-false} \
    NGINX_SSL_PORT=${NGINX_SSL_PORT:-443} \
    NGINX_PORT=${NGINX_PORT:-80} \
    # You're required to add your own SSL certificates/keys to the `./nginx/ssl` directory
    # and modify the env vars below in .env if HTTPS_ENABLED is true.
    NGINX_SSL_CERT_FILENAME=${NGINX_SSL_CERT_FILENAME:-dify.crt} \
    NGINX_SSL_CERT_KEY_FILENAME=${NGINX_SSL_CERT_KEY_FILENAME:-dify.key} \
    NGINX_SSL_PROTOCOLS=${NGINX_SSL_PROTOCOLS:-TLSv1.1} \
    NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-auto} \
    NGINX_CLIENT_MAX_BODY_SIZE=${NGINX_CLIENT_MAX_BODY_SIZE:-15M} \
    NGINX_KEEPALIVE_TIMEOUT=${NGINX_KEEPALIVE_TIMEOUT:-65} \
    NGINX_PROXY_READ_TIMEOUT=${NGINX_PROXY_READ_TIMEOUT:-3600s} \
    NGINX_PROXY_SEND_TIMEOUT=${NGINX_PROXY_SEND_TIMEOUT:-3600s} \
    NGINX_ENABLE_CERTBOT_CHALLENGE=${NGINX_ENABLE_CERTBOT_CHALLENGE:-false} \
    CERTBOT_DOMAIN=${CERTBOT_DOMAIN:-}

RUN sed -i 's/\r$//' /dify-docker-entrypoint.sh
RUN chmod +x /dify-docker-entrypoint.sh

ENTRYPOINT [ "/dify-docker-entrypoint.sh" ]